/**
 * @date 2020/3/28 21:46
 */
public class Demo {

    public synchronized void test1() throws InterruptedException {
        System.out.println(Thread.currentThread().getName()+"in");
        Thread.sleep(3000);
        System.out.println(Thread.currentThread().getName()+"out");
    }

    public static void main(String[] args) throws InterruptedException {
        Demo demo = new Demo();
        Thread thread1 = new Thread(()->{
            try {
                demo.test1();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        Thread thread2 = new Thread(()->{
            try {
                demo.test1();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        thread1.start();
        Thread.sleep(1000);
        thread2.start();
        thread1.interrupt();
    }
}
